import { defineConfig } from 'vite'
import uni from '@dcloudio/vite-plugin-uni'
import path from 'path'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    uni(),
  ],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src'),
      '~': path.resolve(__dirname)
    }
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: '@import "@/uni.scss";'
      }
    }
  },
  build: {
    // 解决 loadBabelMod 问题的构建配置
    target: 'es2015',
    rollupOptions: {
      output: {
        manualChunks: undefined
      }
    }
  },
  esbuild: {
    // 确保 ES 模块正确处理
    target: 'es2015'
  },
  optimizeDeps: {
    // 预构建依赖，避免运行时错误
    include: [
      'vue',
      '@climblee/uv-ui'
    ]
  }
})
